package ObjectVC;

import java.util.ArrayList;

import javax.swing.JOptionPane;

//not relevant
public aspect Commit {	
	after(Object obj) : set(* *.*) && args(obj) && withincode(* *.*(..)) 
		&& !within(ObjectVC.*) && !within(DB.*){
		if (null != obj && VCMode.Automatic.equals(DB.contains(obj)))
			DB.addVersion(obj,"");
	}
	
	after(Object actualObj, Action action, ArrayList<Object> actionParams): 
		VCOperations.VCops(actualObj, action, actionParams) 
		&& if(action.equals(Action.Commit)){
		if (null != actionParams && actionParams.size()>0){
			Object obj = actionParams.get(0);
			String comment = null;
			if (null != obj && VCMode.Automatic.equals(DB.contains(obj)))
				return;
			if (actionParams.size() > 1)
				comment = (String) actionParams.get(1);
			DB.addVersion(obj,comment);
		}
		else
			JOptionPane.showMessageDialog(null, "Object is null");
	}
}
